package org.spider.thread;

import lombok.Data;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Data
public class ThreadPoolConfig {

    private int corePoolSize;
    private int maxPoolSize;
    private int keepAliveSeconds;
    private int queueCapacity;
    private String taskName;

    public ThreadPoolTaskExecutor initExcutor(){
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(corePoolSize);
        threadPool.setMaxPoolSize(maxPoolSize);
        threadPool.setKeepAliveSeconds(keepAliveSeconds);
        threadPool.setQueueCapacity(queueCapacity);
        threadPool.setThreadNamePrefix(taskName);
//        threadPool.setRejectedExecutionHandler(rejectedExecutionHandler);
        return threadPool;
    }
}
